<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>21.方法的重写</title>
</head>

<body>

</body>
<script>
  class Common {
    sum () {
      return this.data.reduce((t, c) => t + c.price, 0);
    }
    getKey (key) {
      return this.data.filter(item => item.name.includes(key));
    }
  }
  class Controller extends Common {

  }

  class Lesson extends Controller {
    constructor(data) {
      super();
      this.data = data;
    }
    info () {
      return {
        //使用super访问父类方法
        totalPrice: super.sum(),
        data: this.data
      }
    }
    getKey (key) {
      return super.getKey(key).map(item => item.name);
    }
  }
  let data = [
    { name: "js", price: 100 },
    { name: "mysql", price: 212 },
    { name: "vue.js", price: 98 }
  ];
  let hd = new Lesson(data);

  console.log(hd.info().totalPrice); //410
  console.log(hd.getKey('js'));// ['js', 'vue.js']
</script>

</html>